#define _CRT_SECURE_NO_WARNINGS 1


  struct ListNode {
      int val;
      struct ListNode *next;
  };
 
typedef struct ListNode ListNode;
struct ListNode* detectCycle(struct ListNode* head)
{
    ListNode* fast = head;
    ListNode* slow = head;
    while (fast && fast->next)
    {
        slow = slow->next;
        fast = fast->next->next;
        if (slow == fast)
        {
            ListNode* node = head;
            while (node != slow)
            {
                node = node->next;
                slow = slow->next;
            }
            return slow;
        }
    }
    return nullptr;
}